<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        var table = document.createElement('table');
        document.body.appendChild(table);
        for(var i = 0;i < 3;i++) {
            var tr = document.createElement('tr');
            for(var j = 0;j < 3;j++) {
                var td = document.createElement('td');
                td.textContent = i + 1;
                tr.appendChild(td);
            }
            document.querySelector('table').appendChild(tr);
        }

    </script>
</body>
</html>